home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / seabool2.zip / SEABOOL.DOC < prev    next >
Text File  |  1990-02-16  |  25KB  |  658 lines

  1.  
  2.                                                                     pg 1
  3.  
  4.  
  5.                        Seabool Searcher v 1.2 (Seabool.pas)
  6.                        Turbo Pascal 5.0 UNIT source code.
  7.                        copyright 1990 by Peter Neuendorffer
  8.  
  9.  
  10.            Documentation and Progammers Instructions.
  11.               Conditional searching tool.
  12.  
  13.                         by
  14.            Peter Neuendorffer
  15.            1399 Commonwealth Ave apt. 11.
  16.            Allston, MA 02134
  17.  
  18.            license to use commercially:
  19.                    Send check for $50.00 to above address.
  20.                    Algorythym and additional source provided to
  21.                    registered user upon request.
  22.                    All inquiries confidential.
  23.  
  24.  
  25.  
  26.  
  27.  
  28.      Seabool is a Turbo Pascal 5.0 source unit.
  29.      Boolean Short Circuit and Stack Checking compiler options
  30.      must be enabled when compiling.
  31.      files in this PROGRAMMERS package
  32.             seabool.doc    PRINT THIS FILE
  33.             seabool.pas    THE UNIT SOURCE
  34.             somebool.pas   A SAMPLE EXAMPLE FILE
  35.             somebool.exe   SAMPLE EXAMPLE FILE executable.
  36.                              Returns truth value of a conditon in
  37.                                 a sentence.  Bare bones example only.
  38.  
  39.      SERVICES:
  40.          bool_init() procedure
  41.          any_bool()      function     returns truth value of text condition
  42.  
  43.          informational variables are returned after call to bool_init
  44.  
  45.          lowercase  function       converts a string to lower case
  46.          editstring procedure      converts a string to lower case
  47.                                      and removes leading,trailing blanks.
  48.  
  49.  
  50.     NOTE FOLLOWING BUG FIXES IN VERSION 1.1:
  51.         the bool_validation_sit code of 2 is returned if wrong syntax
  52.         the bool_validation_sit code of 4 is returned if always false
  53.         range test corrected in lowercase (#91 is correct number)
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.                                                                     pg 2
  67.                            MANUAL
  68.                        introduction                     pg 3
  69.                        how it can be used               pg 5
  70.                        how to use it in your program    pg 6
  71.                        UNIT specifications              pg 7-10
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.                                                                     pg 3
  133.  
  134.  
  135.                        Introduction
  136.  
  137.  
  138.      Seabool is a Turbo Pascal 5.0 source unit, effecting user
  139.      specified search masks for any data or named program object.
  140.  
  141.      It has two procedures and provides several informational variables.
  142.      This manual contains a description of how a Turbo Pascal
  143.      program using the unit Seabool might appear to the user of
  144.      the program. Then a general description of how seabool is
  145.      used by the programmer of the program.
  146.      Lastly, a reference of proper use of the
  147.      two procedures, and specifications for the variables that
  148.      Seabool also provides. These variables are returned to
  149.      provide relevant information to the end-user-program. Care should
  150.      be taken not to alter their values AT ANY time in the
  151.      end-users program. These actual names should not be declared in the
  152.      calling program,although their associated types may be used.
  153.      They are owned by any UNIT that has "uses seabool" in the
  154.      uses clause.
  155.  
  156.      CAUTION: do not pass to Seabool any substring types, such
  157.      as string[10]. Seabool requires the string type for it's
  158.      input parameters. The maximum recursion depth may need to
  159.      be altered, and stack space increased, as SEABOOL is a
  160.      recursive module. The recursion depth is set at the end
  161.      of the seabool source file and may be altered.
  162.      Because of the power of these calls, it is important that
  163.         (1) the programmer understand how to use the unit.
  164.         (2) that testing of a program implementing the Seabool unit
  165.             be done carefully, and NOT using non-standard output
  166.             devices (for example, a robot interface) for testing
  167.             and/or debugging of the program.
  168.         (3) during testing, all data to be searched should be
  169.             copied to a temporary variable, so as to preserve
  170.             integrity of data.
  171.  
  172.       A quick glossary so we know our terms:
  173.              user:   The person who will be using your Turbo Pascal
  174.                      program without knowledge of your source code.
  175.              end-user-programmer:
  176.                      You: the person who writes the program implementing
  177.                          the Seabool unit.
  178.              author: Me. The author of Seabool unit.
  179.  
  180.                    ---------------------------------------------
  181.              boolean conditon:
  182.              a boolean conditon as used in this unit:
  183.                 Let B..Y be English words in string format.
  184.                      Any construct of B..Y in the following form
  185.                          B
  186.                          B and C ....and  Y
  187.                          B or  C ....or   Y
  188.                          Not B
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.                                                                     pg 4
  199.                           Seabool Introduction (continued)
  200.  
  201.              glossary continued:
  202.  
  203.  
  204.              The words "and" "or" "not" are reserved words.
  205.              B..Y are strings whose leading blanks and trailing blanks
  206.              are ignored.
  207.              Thus, actual examples of a target to be searched for might be:
  208.                     <   Mary      and (Sue or George))>
  209.                     <not George>
  210.                     <George or Mary or Sue and Ralph>
  211.                     <(mary and sue) or not(George and Ralph)>
  212.                     < Ralph   >.
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.             boolean search= the presence (true) or absence (false)
  222.                of a boolean condition in a programmer's search object.
  223.  
  224.              Thus the syntax is EXACTLY the same as an if condition
  225.                 (without the if) in PASCAL, C or BASIC.
  226.              Parentheses may be included to stress or force order.
  227.              If no parentheses the order of precedence is:
  228.                        NOT
  229.                        AND
  230.                        OR
  231.  
  232.              Thus the expression <not a and b or c> is equivalent to
  233.                      ((not a) and b) or c
  234.               ------------------------------------------
  235.            Seabool calls:
  236.               procedure bool_init(target_string);
  237.               function any_bool(USER_DEFINED_PROCEDURE_NAME):boolean;
  238.  
  239.            note:
  240.            In addition to the bool_init procedure, and the any_bool function,
  241.             SEABOOL contains two other routines that it needs. These
  242.             are available to the end_user programmer, but need not
  243.             be called to effect a boolean search. They are
  244.             the function "lowercase(str:string):string;"
  245.             and the procedure "Editstring(var str:string);".
  246.             Syntax and functionality for calls to these services
  247.             are described at
  248.             the very end of this manual.
  249.  
  250.       This unit is currently implemented in all Neubase SHAREWARE
  251.              versions. In its present form, it is implemented in
  252.               the file Neubase6.zip, which is published on
  253.               The Software Connection (508)-921-4864.
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.                                                                     pg 5
  265.                    Seabool Searcher:how it can be used
  266.  
  267.  
  268.       This unit allows the end-user programmer to provide
  269.       smart searching to the user of their program.
  270.       An example:
  271.             The user gets a database written by the end-user programmer.
  272.             The end-user programmer has meanwhile retired from computers
  273.             and is living on a desert island without a telephone or
  274.             address. The user enters in data to his new database.
  275.  
  276.             This hypothetical nifty database has a query option for
  277.             the user. The user may search the database for
  278.             a conditon:
  279.                prompt:     "Search for:"
  280.                user types: "this thing and (that thing or the other thing)".
  281.  
  282.             The database then finds all occurences in the
  283.                database that satisfy the user's request. The
  284.                end-user-programmer (you) need not know ANYTHING
  285.                about the content of "this thing" , "that thing" or
  286.                the "other thing", and in fact no longer answers his mail.
  287.  
  288.            Thus the user of the program can query his database data with
  289.                condtions. You, the end-user programmer need not concern
  290.                yourself with the content or structure of queries.
  291.  
  292.  
  293.  
  294.       A specific example:
  295.              In my program Neubase6.zip, a user may enter in
  296.                   volumes of data in their diary.
  297.                   At some point they may
  298.                   "Search for: (phone and (mary or Sue) and not computer)"
  299.                   The program will find all occurences of data that
  300.                   mention
  301.                       (1) phone
  302.                            and
  303.                       (2) either mary or sue
  304.                       (3) but not computer.
  305.  
  306.       A possible example:
  307.               The user issues a command to a robot.
  308.                  "Command (look up and walk right and not talk)"
  309.               Note that the command "variables" are now not text,
  310.               but actual commands from the user.
  311.  
  312.       A suitable example (not implemented by me):
  313.               problem: search a file for a combination of topics.
  314.                        ex: find all files that mention "this thing
  315.                                           and not that thing".
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.                                                                     pg 6
  331.                        How to use Seabool unit in your
  332.                        Turbo Pascal program application.
  333.  
  334.  
  335.  
  336.  
  337.  
  338.         purpose: evaluate a boolean condition consisting of
  339.                   short text connected by "and" "or" or "not"
  340.                   operators with or without parentheses. The
  341.                   '=' , arithmetic and '>','<', and '<>' operators
  342.                   are not treated by Seabool, and will be considered
  343.                   part of the user text to be searched.
  344.  
  345.                 The Seabool unit contains one procedure and one function,
  346.                 and requires a third routine from the programmer.
  347.                     (a)   BOOL_INIT(target_string);
  348.                     (b)   ANY_BOOL(user_defined_procedure);
  349.                 Calls to these two modules are made in the calling
  350.                 program to
  351.                 coordinate the search for the text condition (target_string)
  352.                 in the search space.
  353.                     (c)  USER_DEFINED_PROCEDURE
  354.                          In addition, the enduser programmer must write a
  355.                 Search primitive as an interface procedure. This procedure
  356.                 is in specified format (see reference section below).
  357.                 It will provide the truth value of strings passed
  358.                 by Seabool. Thus the programmer need not be concerned
  359.                 with the complexity or order of the boolean, only
  360.                 whether a given text constant is "found" or not.
  361.  
  362. *           In the process of their search module,
  363.             The end_user programmer obtains the query (target_string)
  364.             from the user as
  365.             a variable of type string. This is then passed to
  366.             Seabool with the
  367. *           call     bool_init(target_string);
  368.             An error code may then be returned in
  369.                bool_validation_sit:byte;
  370.  
  371. *           If bool_validation_sit<>2 then the string is valid.
  372.  
  373. *            The end_user programmer goes into search loop, and
  374.             during this loop
  375.      *               (1) obtains source string or object.
  376.      *               (2) passes the source string to the
  377.                        USER_DEFINED_PROCEDURE. (a dedicated
  378.                              interface variable
  379.                          of type string global to the USER_DEFINED_PROCEDURE
  380.                          would do it)
  381.  
  382.      *               (3) evokes the function
  383.  
  384.                             any_bool(user_defined_procedure);, where
  385.                            the parameter is the exact same spelling
  386.                            as the NAME of the USER_DEFINED_PROCEDURE.
  387.      *                (4) the truth value of the
  388.                               target_string in the source_string has
  389.                                  been returned as a true or false
  390.                                    in the any_bool function.
  391.  
  392.  
  393.  
  394.  
  395.  
  396.                                                                     pg 7
  397.                      Seabool.pas UNIT specifations
  398.  
  399.       Specifications of all Seabool procedures, functions and
  400.       variables that are to be used by the end-user-programmer.
  401.             _____________________________________________________________
  402. *   procedure
  403.     BOOL_INIT(target_string);
  404.  
  405.                           this initilizes the Seabool search by passing
  406.                           the target_string that contains the
  407.                           boolean condition to be found.
  408.  
  409.                           This is called AFTER the target_string
  410.                              is obtained and BEFORE going into
  411.                              your search loop.It should be called
  412.                              only once for any given target_string.
  413.  
  414.                           Seabool may slightly simplify the
  415.                           target_string
  416.                             after a call to bool_init, but will
  417.                             be functionally identical in lower case
  418.                             to the target_string before the call.
  419.  
  420.                          After calling bool_init, associated information
  421.                          is provided to the programmer, which is described
  422.                          in detail in the reference section of this
  423.                          manual. The end-user-programmer must check
  424.                          bool_validation_sit byte type variable to
  425.                          see that it is not equal to 2 {invalid
  426.                          target string}
  427.             _____________________________________________________________
  428.  
  429. *           variable:   bool_validation_sit: byte;
  430.                             possible values.
  431.                                100             not initialized ever
  432.                                1               boolean is acceptable
  433.                                2               boolean is incorrect
  434.                                          in syntax or too complicated.
  435.  
  436.                                4               boolean is logically
  437.                                                  always false
  438. *  function
  439.    ANY_BOOL(USER_DEFINED_PROCEDURE_NAME):boolean;
  440.          user_defined_procedure_name must correspond exactly to
  441.             the name of the user_defined_procedure written by
  442.             the programmer. Note their may be several such procedures.
  443.             The one the programmer chooses is declared to Seabool based
  444.             on the parameter used in the evokation of the any_bool function.
  445.             If bool_validation_sit IS 2 or 4 AFTER calling
  446.             bool_init, indicating
  447.             an invalid or "always false" target_string,than
  448.             the results of bool should always be false.
  449.             Bool is a function. It returns TRUE if the conditon
  450.             named in the last bool_init(target_string) is present
  451.             in the last interface_source_string passed to the
  452.             USER_DEFINED PROCEDURE.
  453.                  thus if source_string contains "The rain in Spain",
  454.                  and the user target string is '(rain or Spain)'
  455.                      after the code
  456.                          <interface_source_string:=source_string;
  457.                          result:=any_bool(user_defined_procedure);>
  458.                      the result variable would contain boolean TRUE.
  459. *          NOTE ANYBOOL does not deal with leading,trailing blanks, and
  460.               is NOT CASE SENSITIVE.
  461.  
  462.  
  463.  
  464.                                                                  pg 8
  465.                         Seabool UNIT specifications (cont)
  466.             _____________________________________________________________
  467.  
  468. *  USER_DEFINED_PROCEDURE. This is a search primitive the END-USER-
  469.              PROGRAMMER WRITES. It may be declared in the interface
  470.              of your search routine file.
  471.               A FAR call {$F+} compiler option must be invoked
  472.               for this procedure. (see Turbo Pascal manual for
  473.               your version 4.0 to 5.5 for details on F+ compiler option)
  474.  
  475.                 It must be in the following format, although the
  476.                 names of the variables may be the programmer's choice:
  477.                      {$F+}
  478.                      user_defined_procedure(var seabool_target:string;
  479.                                            var found:boolean);
  480.  
  481.                     {$F-}.
  482.                The variable seabool_target must NEVER be altered
  483.                by the end-user programmer. It is provided by Seabool
  484.                unit.
  485.                The procedure must return true or false in "found" variable.
  486.                The routine will be fed various text variables by
  487.                Seabool, which may be one or more of the text objects
  488.                specified in the original target string passed to
  489.                bool_init.
  490.                The programmer is expected to say whether each text
  491.                is "found" in the source being searched. The source
  492.                string or object may be passed to the procedure
  493.                using an interface variable dedicated to this purpose.
  494.              _____________________________________________________________
  495.  
  496. VARIABLES returned after valid call to bool_init (where
  497.               bool_validation_sit <> 2
  498.  
  499.   type {note}
  500.             letter_type: 'a'..#123;{sublist of char}
  501.                          If bool_validation_sit is NOT 2, then
  502.                          the following variables are defined:
  503.  
  504.             _____________________________________________________________
  505.  
  506.   variable name:
  507.                 length_object_hash_table_0:letter_type;
  508.  
  509.   meaning:      number of distinct variables in user boolean.
  510.                 counter relative to 'b'.
  511.                 Thus a value of 'c' indicates two variables were
  512.                              present.
  513.                 variable indexes 'b' to 'y' are supported. Thus your
  514.                 user string may contain up to 24 variables. Any more will
  515.                 return an error code of 2 in bool_validation_sit after
  516.                 a call to bool_init.
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.                                                                     pg 9
  531.                             Seabool UNIT specifications (cont)
  532.             _____________________________________________________________
  533.  
  534.   variable name:
  535.                 search_object_hash_table_0 : array [letter_type] of
  536.                                                     string;
  537.   meaning:      The list of variable values in target_string.
  538.                       thus user_hash_table['b'] contains the
  539.                               first variable etc.
  540.                 Note the indexes of this array are indexed with
  541.                 letters starting with 'b'. If for example, the target_
  542.                 string from the user was <phone and (mary or not sue)>, then
  543.                 the array would be filled after
  544.                 bool_init(target_string); with
  545.                   search_object_hash_table_0['b']='phone';
  546.                   search_object_hash_table_0['c']='mary';
  547.                   search_object_hash_table_0['d']='sue';
  548.                 You need not examine this array to effect the
  549.                 boolean search, but the information is provided.
  550.                 Note all text will be with no leading blanks or
  551.                 trailing blanks, and will be in lower case.
  552.  
  553.  
  554.             _____________________________________________________________
  555.  
  556.   variable name:
  557.                 bool_crit_true : array['a'..#123] of boolean;
  558.  
  559.   meaning:      one to one correspondence to user_hash_table by
  560.                        index. If true, then the associated variable
  561.                           is CRITICAL to the truth value of the boolean.
  562.  
  563.                  thus is bool_crit_true['b'] is true, then the first
  564.                  variable in the user_hash_table array MUST be true
  565.                  for the expression to be true.
  566.  
  567.                  In the above example, after a call to
  568.                  bool_init('phone and (mary or not sue)'); the array
  569.                  would contain
  570.                       bool_crit_true['b']=true
  571.                       bool_crit_true['c']=false
  572.                       bool_crit_true['d']=false
  573.                  Once again, this array need not be referenced to
  574.                  effect a boolean search with bool function.
  575.  
  576.             _____________________________________________________________
  577.  
  578.   variable name:
  579.                 max_bool_recursion_depth: byte;
  580.   meaning:
  581.                 measure of maximum recursion allowed. Every call to
  582.                 the interenal parser increments a counter. If this
  583.                 counter exceeds the max_bool_recursion_depth, then
  584.                 bool_init returns a 2 in bool_validation_sit.
  585.                 No other variables returned will be defined.
  586.                 Max_bool_recursion_depth has been set to 24 in the
  587.                 Initialization of the Seabool unit {at the end of
  588.                 the source file}. If altered, this number should
  589.                 be hard coded in the Seabool source.
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.                                                                     pg 10
  597.                           Seabool UNIT specifications (cont)
  598.           _____________________________________________________________
  599.  
  600.       variable name:
  601.                and_op,or_op :boolean;
  602.  
  603.                After a call to bool_init, the values of
  604.                   and_op, or_op have the following meanings:
  605.  
  606.                    and_op=true   or_op=true      meaning
  607.                    ___________   __________      _______
  608.                       yes          yes           If operators in
  609.                                                target_string, then
  610.                                                  only AND operator
  611.                                                  present.
  612.  
  613.                       no            yes           If operators in
  614.                                                  target_string, then
  615.                                                   only OR operator
  616.                                                    present.
  617.  
  618.                       no             no           If operators in target
  619.                                                    string, the NOT
  620.                                                     operator is
  621.                                                     present.
  622.  
  623.             _____________________________________________________________
  624.             Once again, these variables need not be examined by the
  625.             end-user programmer to effect a boolean search using
  626.             bool and bool_init.
  627.  
  628. *      Other services provided by Seabool: {routines used by Seabool,
  629.                   that need not be used by the end user programmer,
  630.                   but are independently available}
  631.  
  632.            function lowercase(str:string):string;
  633.                   Function returns the string "str" in lowercase
  634.                      without affecting non-alphabetic characters.
  635.  
  636.            procedure Editstring(var str:string);
  637.                   Converts a string "str" to lowercase and removes
  638.                      any leading or trailing blanks from the string.
  639.            NOTE, IF YOU USE THESE TWO SERVICES
  640.            TO SUPPORT ANY STRING TYPE THAT IS OF NOT TYPE
  641.            string, SEABOOL must be compiled with the relaxed string
  642.            checking compiler option enabled. {see Turbo Pascal
  643.            manual, or THE COMPLETE TURBO PASCAL REFERENCE by Stephen
  644.            K. O'brien).
  645.  
  646. * QUICK REFERENCE:
  647.            define search primitive
  648.            obtain target_string
  649.            call bool_init(target_string)
  650.            examine bool_validation_sit
  651.                     2 means bad
  652.                     4 means always false
  653.           pass each source string to a variable available to
  654.                 your search primitive
  655.           call result:=any_bool(search primitive name);
  656.                  result will be true if target_string condition is
  657.                     satisfied in source string,
  658.                 false if not.